import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Compa {
    //测试arrayList插入速度和LinkedList插入速度
    public static void testArrayList() {
        List<Integer> list =new ArrayList<Integer>();

        for (int i = 0; i < 20000; i++) {
            list.add(i);
        }
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            list.add(100, i);
        }
        System.out.println(list.size());
        long endTime = System.currentTimeMillis();
        int time=(int) (endTime - startTime);
        System.err.println("arrayList:运行时间:" + time + "ms");
        long Time1=System.currentTimeMillis();
        for(int i=0;i<100;i++){
            list.remove(100);
        }
        long Time2=System.currentTimeMillis();
        int time1=(int)(Time2-Time1);
        System.out.println("删除100条用时："+time1+"ms");
    }


    public static void testLinkedList() {
        List<Integer> list =new LinkedList<Integer>();
        for (int i = 0; i < 20000; i++) {
            list.add(i);
        }
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            list.add(100, i);
        }
        System.out.println(list.size());
        long endTime = System.currentTimeMillis();
        int time=(int) (endTime - startTime);
        System.err.println("linkedList:运行时间:" + time + "ms");
        long Time1=System.currentTimeMillis();
        for(int i=0;i<100;i++){
            list.remove(100);
        }
        long Time2=System.currentTimeMillis();
        int time1=(int)(Time2-Time1);
        System.out.println("删除100条用时："+time1+"ms");
    }

    public static void main(String[] args) {
        Compa testSpead_list = null;
        testArrayList();
        testLinkedList();
    }
}
